package cn.sylinx.horm.resource.liquor.ext;

import java.util.Collection;
import java.util.Iterator;

class ForeachFunctions {

    public static String foreach(Collection<?> input, String openSymbolStr, String splitSymbolStr, String closeSymbolStr, String quote) {

        if (input == null || input.isEmpty()) {
            return "";
        }

        Iterator<?> it = input.iterator();

        StringBuilder sb = new StringBuilder();
        sb.append(openSymbolStr);
        while (it.hasNext()) {
            sb.append(quote).append(it.next().toString()).append(quote).append(splitSymbolStr);
        }
        int splitLen = splitSymbolStr.length();
        int totalLen = sb.length();

        sb.delete(totalLen - splitLen, totalLen);
        sb.append(closeSymbolStr);

        return sb.toString();
    }
}
